﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zocono.Infrastructure.Common;
using Zocono.WCS.Domain.EntityInfo;
using Zocono.WCS.Domain.PlcConnectPoolDomain;

namespace Zocono.WCS.Domain.HynnStateUpDomain
{
    public class HynnStateUpService : IHynnStateUpService
    {

        private readonly ILogUtil _logUtil;
        private readonly IRedisHelper _IRedisHelper;

        public HynnStateUpService(ILogUtil logUtil, IRedisHelper redisHelper)
        {
            _logUtil = logUtil;
            _IRedisHelper = redisHelper;
        }

        public List<HynReturnState> GetAllHynnStateInfoAsync()
        {
            try
            {
                var states = _IRedisHelper.GetStringKey<List<HynReturnState>>("HynnState");
                return states;
            }
            catch (Exception ex)
            {
                _logUtil.Error($"获取恒翼能状态数据报错，ex = {ex.Message}");
                return new List<HynReturnState>();
            }
        }

        public bool InsertHynnStateInfoAsync(List<HynReturnState> hynReturnStates)
        {
            try
            {
                var states = _IRedisHelper.SetStringKey("HynnState", hynReturnStates, TimeSpan.FromMinutes(100));
                return states;
            }
            catch (Exception ex)
            {
                _logUtil.Error($"获取恒翼能状态数据报错，ex = {ex.Message}");
                return false;
            }
        }
    }
}
